//添加权限
export const addRoles = async(req,res)=>{
    const { name, path, action  } = req.body
    if(!name) return res.fail('用户名不能为空')
    if(!path) return res.fail('路径不能为空')
    try{
        const result = {
            name,
            path
        }
        if(action) result.action = action
        await req.db.isRoles.create({
            data: result
        })
        res.send({success: true, message: '添加成功'})
    }catch(e){
        console.log(e)
        res.fail({success: false, message: '添加失败'})
    }
}
//获取全部角色权限
export const getAllRoles = async(req,res)=>{
    try{
        const all = await req.db.isRoles.findMany()
        res.send({success: true, data:all })
    }catch(e){
        console.log(e)
        res.fail({success: false, message: '获取失败'})
    }
}
//删除权限
export const delRoles = async(req,res)=>{
    const { id } = req.body
    if(!id) return  res.fail('id不能为空')
    try{
        await req.db.isRoles.delete({
            where:{
                id:Number(id)
            }
        })
        res.send({success:true , message:'删除成功'})
    }catch(e){
        console.log(e)
        res.fail({success:false , message:'删除失败'})
    }
}